
<template>
  <div class="main">
      <el-table :data="tableData" style="width: 80%">
      <el-table-column prop="id" label="学号" width="180" />
      <el-table-column prop="name" label="姓名" width="180" />
      <el-table-column prop="score" label="分数" width="180" />
      <el-table-column prop="desc" label="评语" width="180" />
      <el-table-column fixed="right" label="Operations" >
        <template #default="scope">
          <el-button link type="primary" size="small">编辑</el-button>
          <el-button link type="danger" size="small" @click="handleDelete(scope.row.id)">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>

  <!-- 编辑模态框 开始 -->
  <el-dialog v-model="dialogFormVisible" title="编辑" width="500">
      <!-- {{ form }} -->
      <el-form :model="form">
        <el-form-item label="id" :label-width="formLabelWidth">
          <el-input v-model="form.id" disabled autocomplete="off" />
        </el-form-item>
        <el-form-item label="姓名" :label-width="formLabelWidth">
          <el-input v-model="form.name" autocomplete="off" />
        </el-form-item>
        <el-form-item label="分数" :label-width="formLabelWidth">
          <el-input-number :min="0" :max="100" v-model="form.score" autocomplete="off" />
        </el-form-item>
        <el-form-item label="评语" :label-width="formLabelWidth">
          <el-input v-model="form.desc" type="textarea" autocomplete="off" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取消</el-button>
          <el-button type="primary" @click="editUser">
            确认
          </el-button>
        </div>
      </template>
    </el-dialog>
  <!-- 编辑模态框 结束 -->

   <!-- 路由跳转 -->
   <div class="myRouter">
      <RouterLink to="/">Go to Home</RouterLink>
      <RouterLink to="/about">Go to About</RouterLink>
      <RouterLink to="/login">Go to Login</RouterLink>
    </div>
    <!-- 匹配到的路由展示的位置 -->
    <RouterView />
</template>

<script setup>
import { ref } from 'vue'
  const tableData =ref( [
    {
      id: '001',
      name: '张三',
      score: 90,
      desc:"很优秀"
    },
    {
      id: '002',
      name: '李四',
      score: 80,
      desc:"优秀"
    },
    {
      id: '003',
      name: '王五',
      score: 70,
      desc:"良好"
    },
    {
    id: '004',
    name: 'TOM',
    score: 60,
    desc:"及格"
    },
  ])

  const formLabelWidth = '140px'
const form = ref({});
// 编辑的模态框
const dialogFormVisible = ref(false);
  function handleDelete (id) {
  // console.log('🤡 CC - handleDelete - id:', id);
  // 发送请求 delStudentById(id);
  tableData.value.forEach((e, index) => {
    if (e.id == id) {
      // console.log('🤡 CC - tableData.value.forEach - index:', index);
      // console.log('🤡 CC - handleDelete - e:', e);
      // 根据下标删除数组元素
      tableData.value.splice(index, 1);
    }
  })
}
// 打开编辑表单
function handleEdit (row) {
  // console.log('🤡 CC - handleEdit - row:', row);
  form.value = row;
  dialogFormVisible.value = true
}
// 提交编辑表单
function editUser () {
  // 将数据发送到后台
  // editStudentById(form.value);
  dialogFormVisible.value = false
}
</script>
<style>
  .main{
    height: 100%;
    text-align: center;
    border: 1px solid royalblue;
    padding-left: 20%;
    padding-top: 15%;
  }
</style>

